package com.seatiger.structure.stack;

import java.util.Random;

/**
 * 测试
 */
public class StackMain {
    public static void main(String[] args) {
        int opCount = 100000;
        ArrayStack arrayStack = new ArrayStack<Integer>();
        double time1 = testStack(arrayStack, opCount);
        System.out.println("ArrayStack, time:" + time1 + "s.");
        LinkedListStack linkedListStack = new LinkedListStack<Integer>();
        double time2 = testStack(linkedListStack, opCount);
        System.out.println("LinkedListStack, time:" + time2 + "s.");
    }

    private static double testStack(Stack stack, int opCount) {
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            stack.push(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            stack.pop();
        }
        long endTime = System.nanoTime();
        return (endTime - startTime) / 1_000_000_000.0;
    }

    public static void test1() {
        Stack<Integer> stack = new LinkedListStack<>();
        for (int i = 0; i< 5; i++) {
            stack.push(i);
            System.out.println(stack);
        }
        stack.pop();
        System.out.println(stack);
    }
}


